public class Work07 {

    private static int[] nums = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12};
    private static int count = 0;

    private static void swap(int[] nums, int a, int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }

    private static void dfs(int start, int end) {
        int i;
        if (start == end) {

            int sum = nums[1] + nums[3] + nums[6] + nums[9];
            if (nums[1] + nums[4] + nums[8] + nums[10] == sum && nums[2] + nums[3] + nums[4] + nums[5] == sum &&
                    nums[2] + nums[6] + nums[7] + nums[10] == sum && nums[5] + nums[7] + nums[8] + nums[9] == sum) {
                count++;
            } else {
                for (i = start; i <= end; i++) {
                    swap(nums, start, i);
                    dfs(start + 1, end);
                    swap(nums, start, i);
                }
            }

        }
    }


    public static void main(String[] args) {
        dfs(1, 10);
        System.out.println(count);
    }
}
